using ICSharpCode.SharpZipLib.Zip;
using MicroMsg.Common.Algorithm;
using MicroMsg.Common.Utils;
using MicroMsg.Scene;
using MicroMsg.Storage;
using System;
using System.IO;
using System.IO.IsolatedStorage;
namespace MicroMsg.Manager
{
	public class PackageDataMgr
	{
		private const string TAG = "PackageDataMgr";
		public static void savePacageDataList(PacageDataList pageList)
		{
			GConfigMgr.write<PacageDataList>(pageList);
		}
		public static PacageDataList getPacageDataList()
		{
			PacageDataList pacageDataList = GConfigMgr.read<PacageDataList>();
			double num = 0.0;
			if (pacageDataList != null)
			{
				num = Util.getNowMilliseconds() - pacageDataList.lastUpdateTime;
			}
			if (pacageDataList == null || num - 51840000000.0 > 0.0 || pacageDataList.dataList.get_Count() <= 0)
			{
				GetPackageListMgr.getPackageList(1);
			}
			return pacageDataList;
		}
		public static string getPackBigFileName(PacageData package)
		{
			if (package == null)
			{
				return null;
			}
			return StorageIO.getGlobaDataPath() + "/" + MD5Core.GetHashString(package.nId + package.nVersion) + ".jpg";
		}
		public static string getZipFileName(PacageData package)
		{
			if (package == null)
			{
				return null;
			}
			return string.Concat(new object[]
			{
				StorageIO.getGlobaDataPath(),
				"/",
				package.nId,
				".zip"
			});
		}
		public static bool isPackBigFileNameExist(PacageData package)
		{
			string packBigFileName = PackageDataMgr.getPackBigFileName(package);
			return StorageIO.fileExists(packBigFileName);
		}
		public static string getBigFile(PacageData package)
		{
			if (package == null)
			{
				return null;
			}
			string packBigFileName = PackageDataMgr.getPackBigFileName(package);
			if (StorageIO.fileExists(packBigFileName))
			{
				return packBigFileName;
			}
			new NetSceneDownLoadPackage().doScene(package);
			return null;
		}
		public static MemoryStream zipParas(string fileName, string strKeyword)
		{
			MemoryStream memoryStream = null;
			using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
			{
				IsolatedStorageFileStream baseInputStream = userStoreForApplication.OpenFile(fileName, 3, 1);
				ZipInputStream zipInputStream = new ZipInputStream(baseInputStream);
				byte[] array = new byte[2048];
				ZipEntry nextEntry;
				while ((nextEntry = zipInputStream.GetNextEntry()) != null)
				{
					if (nextEntry != null)
					{
						string name = nextEntry.Name;
						if (name != string.Empty && name.Contains(strKeyword))
						{
							if (memoryStream == null)
							{
								memoryStream = new MemoryStream();
							}
							while (true)
							{
								int num = zipInputStream.Read(array, 0, array.Length);
								if (num <= 0)
								{
									break;
								}
								memoryStream.Write(array, 0, num);
							}
						}
					}
				}
			}
			return memoryStream;
		}
		public static bool saveBigImg(MemoryStream imgStream, string fileName)
		{
			return imgStream != null && imgStream.get_Length() > 0L && StorageIO.writeToFile(fileName, imgStream.ToArray(), false);
		}
	}
}
